package com.gitee.neuray.security.admin.staff.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gitee.neuray.security.admin.staff.vo.StaffOrg;
import com.gitee.neuray.security.admin.staff.vo.StaffPageExcelVo;
import com.gitee.neuray.security.admin.staff.vo.StaffVo;
import com.gitee.neuray.security.common.msg.TableResultResponse;
import com.gitee.neuray.security.common.util.ExcelUtils;
import com.gitee.neuray.security.common.util.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.gitee.neuray.security.admin.staff.biz.StaffBiz;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;



/**
 * 人员信息管理
 *
 * @author fanj
 * @email ${email}
 * @date 2020-03-02 16:29:35
 */
@RestController
@RequestMapping("staff")
public class StaffController{
    @Autowired
    private StaffBiz staffBiz;

    /**
    * 分页获取列表
    * @param params
    * @return
    */
    @RequestMapping(value = "page" ,method = RequestMethod.GET)
    public TableResultResponse queryPage(@RequestParam Map<String,Object> params){
        //查询列表数据
        Query query = new Query(params);
        return staffBiz.page(query);
    }

    @RequestMapping(value = "fingOrgByTree",method = RequestMethod.GET)
    public List<StaffOrg> fingOrgByTree(){
        return staffBiz.getStaffByTree();
    }

    @RequestMapping(value = "fingStaffByOrg",method = RequestMethod.POST)
    public List<StaffVo> fingStaffByOrg(@RequestBody StaffOrg staffOrg){
        return staffBiz.findStaffByOrg(staffOrg);
    }

    @RequestMapping(value = "fingOrgByOrg",method = RequestMethod.POST)
    public List<StaffOrg> fingOrgByOrg(@RequestBody StaffOrg staffOrg){
        return staffBiz.findOrgByOrg(staffOrg);
    }

    @RequestMapping(value = "insertStaff",method = RequestMethod.POST)
    public void insertStaff(@RequestBody StaffVo StaffVo){
        staffBiz.insertStaff(StaffVo);
    }

    @RequestMapping(value = "updateStaff",method = RequestMethod.POST)
    public void updateStaff(@RequestBody StaffVo StaffVo){
        staffBiz.updateStaff(StaffVo);
    }

    @RequestMapping(value = "deleteStaff",method = RequestMethod.POST)
    public void deleteStaff(@RequestBody StaffVo StaffVo){
        staffBiz.deleteStaff(StaffVo);
    }

    @RequestMapping(value = "findByUserId",method = RequestMethod.POST)
    public List<StaffVo> findByUserId(@RequestBody StaffOrg staffOrg){
        return staffBiz.findStaffByOrg(staffOrg);
    }

    @RequestMapping(value = "export",method = RequestMethod.GET)
    public void export(@RequestParam Map<String,Object> params, HttpServletResponse response)throws Exception{
        Query query = new Query(params);
        List data = staffBiz.nopage(query);
        List<StaffPageExcelVo> execlData = JSONArray.parseArray(JSONObject.toJSONString(data),StaffPageExcelVo.class);
        ExcelUtils.export(response,"人员信息管理",
                execlData,
                StaffPageExcelVo.class);
    }
}
